package com.naiterui.ehp.bs.wechat.param.custom;

import org.apache.commons.lang3.StringUtils;

import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMsg;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomVoice;

import lombok.Data;

/**
 * 语音消息
 *
 * @author zhoupeipei
 * @date 2019-07-05 15:09
 * @since 1.0.0
 */
@Data
public class VoiceMsgParam extends BaseCustomParam {
    private static final long serialVersionUID = 3755725800400158112L;
    /**
     * 多媒体文件在微信服务器上的id</p>
     * <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     * <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    private String mediaId;

    /**
     * 参数构造器
     *
     * @param openId  用户openId
     * @param mediaId 语音文件在微信服务器上的id
     *                <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     *                <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    public VoiceMsgParam(String openId, String mediaId) {
        super.setOpenId(openId);
        super.setMsgType(WeChatConstant.KefuMsgType.VOICE);
        this.mediaId = mediaId;
    }

    @Override
    public CustomMsg getCustomProtocol() {
        if (super.validate() && StringUtils.isNotBlank(mediaId)) {
            CustomVoice customVoice = new CustomVoice(mediaId);
            return new CustomMsg(getOpenId(), customVoice, getMsgType());
        }
        return null;
    }
}
